export const SocketTask = wx.connectSocket({
  url: 'ws://127.0.0.1:9998',
  header:{
    'content-type': 'application/json'
  },
  protocols: ['protocol1'],
})

export const connetSocket = ()=>{
  SocketTask.onOpen(()=>{
    console.log("sokect服务启动成功");
  })
  
  /*
  SocketTask.onMessage(res=>{
    // console.log(res);
    let {data} = res
    data = JSON.parse(data)
    // console.log(data);
    if(data.hasNewMsg){

    }
  })
  */
}

// data:{hasNewMsg:true,chatRoomId:}
export const send = (data)=>{
  data = JSON.stringify(data)

  SocketTask.send({
    data
  })
}
